package com.example.tys.baseapplication;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import com.example.tys.baseapplication.util.NotificationHelper;

/**
 * @author tys
 */
public class NotifyActivityTest extends AppCompatActivity {

    private String TAG = "NotifyActivityTest";
    private int i = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notify_test);
        Log.e(TAG, "onCreate");


        if (BuildConfig.LAUNCHER_FROM.equals(getMetaData())) {
            Log.e(TAG, "正常启动(点击每项通知栏启动)");
        } else {
            Intent intent = getIntent();
            String launcherFrom = intent.getStringExtra("LAUNCHER_FROM");
            switch (launcherFrom) {
                case "notify":
                    Log.e(TAG, "notify 启动");
                    break;
                default:
                    finish();
            }
        }
        Intent intent = getIntent();
        String title = intent.getStringExtra("title");
        String body = intent.getStringExtra("body");
        Log.e(TAG, title + " _ " + body);
    }

    private String getMetaData() {
        String from = "";
        try {
            ActivityInfo info = getPackageManager().getActivityInfo(getComponentName(), PackageManager.GET_META_DATA);
            from = info.metaData.getString("LAUNCHER_FROM");
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return from;
    }

    @Override
    protected void onDestroy() {
        Log.e(TAG, "onDestroy");
        super.onDestroy();
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        Log.e(TAG, "onNewIntent");
    }

    public void notofy1(View view) {
        NotificationHelper notificationHelper = new NotificationHelper(getApplication());
        NotificationCompat.Builder builder = notificationHelper.getNotification("title" + i, "body1" + i,
                NotificationHelper.NotifyType.MIN_TYPE);
        notificationHelper.notify(i++, builder);
    }

    public void notofy2(View view) {
        NotificationHelper notificationHelper = new NotificationHelper(getApplication());
        NotificationCompat.Builder builder = notificationHelper.getNotification("title" + i, "body1" + i,
                NotificationHelper.NotifyType.LOW_TYPE);
        notificationHelper.notify(i++, builder);
    }

    public void notofy3(View view) {
        NotificationHelper notificationHelper = new NotificationHelper(getApplication());
        NotificationCompat.Builder builder = notificationHelper.getNotification("title" + i, "body1" + i,
                NotificationHelper.NotifyType.NORMAL_TYPE);
        notificationHelper.notify(i++, builder);
    }

    public void notofy4(View view) {
        NotificationHelper notificationHelper = new NotificationHelper(getApplication());
        NotificationCompat.Builder builder = notificationHelper.getNotification("title" + i, "body1" + i,
                NotificationHelper.NotifyType.HIGH_TYPE);
        notificationHelper.notify(i++, builder);

    }

    public void notofy5(View view) {
        NotificationHelper notificationHelper = new NotificationHelper(getApplication());
        NotificationCompat.Builder builder = notificationHelper.getNotification("title" + i, "body1" + i,
                NotificationHelper.NotifyType.MAX_TYPE);
        notificationHelper.notify(i++, builder);
    }


}
